<div id="copymain">
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title" id="myModalLabel">产品角色复制</h4>
</div>
<div class="modal-body">
    <input type="hidden" id="did" value="{if isset($id)}{$id}{/if}">
    <div class="row">
        <div class="col-md-12">
            <div class="alert alert-dismissable alert-info">
                <button type="button" class="close">×</button>
                <p></p>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-hover ntTable" v-cloak>
                <tbody>
                    <tr>
                        <td>{:lang("model")}<span class="required"></span></td>
                        <td colspan="3"><input type="text" class="form-control" v-model="prodata.model"></td>
                        <td>{:lang("package")}</td>
                        <td><input type="number" class="form-control text-right" v-model="prodata.package_qty"></td>
                    </tr>
                    <tr>
                        <td>{:lang("quantity")}/CTN</td>
                        <td><input type="number text-right" class="form-control" v-model="prodata.qty"></td>
                        <td>{:lang("dimension")}/CTN</td>
                        <td><input type="text" class="form-control text-center" v-model="prodata.ctn_size"></td>
                        <td>{:lang("weight")}/CTN</td>
                        <td><input type="number" class="form-control text-right" v-model="prodata.ctn_kgs"></td>
                    </tr>
                    <tr>
                        <td>{:lang("description")}</td>
                        <td colspan="5"><input type="text" class="form-control" v-model="prodata.ctn_note"></td>
                    </tr>
                    <tr>
                        <td>{:lang("barcode")}</td>
                        <td colspan="5">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="input-group">
                                        <input type="text" class="form-control" placeholder="条码自动生成" v-model="prodata.codebar" readonly />
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button"><span class="glyphicon glyphicon-cloud-download" style="margin:0"></span></button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr v-for="(item,index) in prodata.feature">
                        <td>{{item.name}}</td>
                        <td colspan="5"><input type="text" class="form-control" v-model="prodata.feature[index].value"></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">
        <span class="glyphicon glyphicon-remove"></span>{:lang('close')}
    </button>
    <button type="button" class="btn btn-primary" @click="savefun" style="padding-left:24px;padding-right:24px">
        <span class="glyphicon glyphicon-floppy-disk"></span>{:lang('save')}
    </button>
</div>
</div>

<script>
    new Vue({
        el:'#copymain',
        data:()=>({
            prodata:{feature:[]}
        }),
        mounted(){
            this.getdata()
        },
        methods:{
            getdata(){
                new Promise((res,rej)=>{
                    $.ajax({
                        url:'/admin/product/detailCopy',
                        data:{
                            request:'ajax',
                            id:$('#did').val()
                        },
                        type:'post',
                        success:(data)=>{
                            data = JSON.parse(data)
                            this.prodata=data
                            res()
                        }
                    }).then(()=>{
                        $.ajax({
                            url:'/admin/api/getProcharCodebar',
                            type:'post',
                            success:(data)=>{
                                this.prodata.codebar=data
                            }
                        })
                    })
                })
            },
            savefun(){
                $.ajax({
                    url:'/admin/product/detailCopyInsert',
                    type:'post',
                    data:this.prodata,
                    success:(data)=>{
                        data = JSON.parse(data)
                        if(data.status==1){
                            change_mes_type('.alert',data.status)
                            $('.alert').show()
                            $('.alert p').html('*'+data.msg+'<br>')
                                location.reload()
                        }else{
                            change_mes_type('.modal-body .alert',data.status)
                            $('.modal-body .alert').show()
                            $('.modal-body .alert p').html('*'+data.msg+'<br>')
                        }
                    }
                })
            }
        }
    })
</script>